]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
osdWindow: Take per-monitor information in show and add showAll, showOne
authorSebastian Wick <sebastian.wick@redhat.com>
Wed, 2 Jul 2025 10:23:51 +0000 (12:23 +0200)
committerSebastian Wick <sebastian.wick@redhat.com>
Sun, 3 Aug 2025 01:32:35 +0000 (03:32 +0200)
The current API only supports showing an OSD on all monitors or on one
monitor. This change makes it possible to show the OSD on any
combination of monitors while providing simpler functions for the common
usages.

It still retains the single-event character and cancels previous OSDs on
unaffected monitors.

We will require this for the screen brightness keyboard shortcuts in the
future.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3751>

js/ui/osdWindow.js
js/ui/shellDBus.js
js/ui/status/volume.js
js/ui/windowManager.js

index 818595f981d5f89b80e93ddca6db8580eceec6f5..24590d5427b9cb2286d9a1b7002789b32e9272a5 100644 (file)
@@ -171,20 +171,28 @@ export class OsdWindowManager {
         this._osdWindows[monitorIndex].show();
     }
 
-    show(monitorIndex, icon, label, level, maxLevel) {
-        if (monitorIndex !== -1) {
-            for (let i = 0; i < this._osdWindows.length; i++) {
-                if (i === monitorIndex)
-                    this._showOsdWindow(i, icon, label, level, maxLevel);
-                else
-                    this._osdWindows[i].cancel();
-            }
-        } else {
-            for (let i = 0; i < this._osdWindows.length; i++)
+    show(icon, label, levels) {
+        for (let i = 0; i < this._osdWindows.length; i++) {
+            if (levels[i]) {
+                const {level, maxLevel = -1} = levels[i];
                 this._showOsdWindow(i, icon, label, level, maxLevel);
+            } else {
+                this._osdWindows[i].cancel();
+            }
         }
     }
 
+    showOne(monitorIndex, icon, label, level, maxLevel) {
+        this.show(icon, label, {
+            [monitorIndex]: {level, maxLevel},
+        });
+    }
+
+    showAll(icon, label, level, maxLevel) {
+        for (let i = 0; i < this._osdWindows.length; i++)
+            this._showOsdWindow(i, icon, label, level, maxLevel);
+    }
+
     hideAll() {
         for (let i = 0; i < this._osdWindows.length; i++)
             this._osdWindows[i].cancel();
index bbddefb3d6ee5213538f0e71da7e4574646211d5..0e2cf2b59e573531bea3b4e078239c37e4acbe6e 100644 (file)
@@ -135,17 +135,18 @@ export class GnomeShell {
             icon: serializedIcon,
         } = params;
 
-        let monitorIndex = -1;
-        if (connector) {
-            const monitorManager = global.backend.get_monitor_manager();
-            monitorIndex = monitorManager.get_monitor_for_connector(connector);
-        }
-
         let icon = null;
         if (serializedIcon)
             icon = Gio.Icon.new_for_string(serializedIcon);
 
-        Main.osdWindowManager.show(monitorIndex, icon, label, level, maxLevel);
+        if (connector) {
+            const monitorManager = global.backend.get_monitor_manager();
+            const monitorIndex =
+                monitorManager.get_monitor_for_connector(connector);
+            Main.osdWindowManager.showOne(monitorIndex, icon, label, level, maxLevel);
+        } else {
+            Main.osdWindowManager.showAll(icon, label, level, maxLevel);
+        }
         invocation.return_value(null);
     }
 
index e2fa9a207eae92eae9935e8da1d01b9c1c46b134..89d3bebec1a863ed84dd717001665983599f5d1a 100644 (file)
@@ -281,7 +281,7 @@ const StreamSlider = GObject.registerClass({
         const gicon = new Gio.ThemedIcon({name: this.getIcon()});
         const level = this.getLevel();
         const maxLevel = this.getMaxLevel();
-        Main.osdWindowManager.show(-1, gicon, null, level, maxLevel);
+        Main.osdWindowManager.showAll(gicon, null, level, maxLevel);
     }
 });
 
index c05a52ea15e2514459b6a6718e82acea97a14658..e48e6d3fcfc1fb3868ec8fa53eea56190cd1c3b5 100644 (file)
@@ -887,7 +887,7 @@ export class WindowManager {
         global.display.connect('show-pad-osd', this._showPadOsd.bind(this));
         global.display.connect('show-osd', (display, monitorIndex, iconName, label) => {
             let icon = Gio.Icon.new_for_string(iconName);
-            Main.osdWindowManager.show(monitorIndex, icon, label, null);
+            Main.osdWindowManager.showOne(monitorIndex, icon, label);
         });
 
         global.display.connect('init-xserver', (display, task) => {